package io.demo.message.util;

import io.demo.message.domain.Address;
import io.demo.message.domain.Customer;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import org.apache.commons.lang3.RandomUtils;

class RandomCustomerSupplier implements Supplier<Customer> {

  private RandomStringBuilder randomStringBuilder;

  RandomCustomerSupplier() {
    this.randomStringBuilder = RandomStringBuilder.newBuilder()
        .useUpperCase()
        .useLowerCase()
        .useWhitespace();
  }

  @Override
  public Customer get() {
    List<Address> list = new ArrayList<>();
    IntStream.range(0, RandomUtils.nextInt(10, 100))
        .forEach(i -> list.add(TestingModels.address()));

    return Customer.builder()
        .id(RandomUtils.nextLong())
        .genderType(TestingModels.genderType())
        .firstName(randomStringBuilder.build(10, 30))
        .lastName(randomStringBuilder.build(10, 40))
        .addresses(list)
        .build();
  }
}
